import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:panda/base/Constant.dart';
import 'package:panda/base/SignType.dart';
import 'package:panda/http/Api.dart';
import 'package:panda/http/HttpUtil.dart';
import 'package:panda/set/ApplyShouQuan.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';
import 'package:panda/util/SignUtil.dart';
class ShouQuanPage extends StatefulWidget {
  ShouQuanPage({Key key}) : super(key: key);

  @override
  _ShouQuanPageState createState() => _ShouQuanPageState();
}

class _ShouQuanPageState extends State<ShouQuanPage> {
  String token="";
  String url="";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value){
      token=value;
          getData();

    });
  }
   getData() async {
    Map map = new Map();
    map['token'] = token;
    map['sign_type'] = SignType.GET_SHOUQUAN;
    Response<String> response =
        await HttpUtil().post(Api.GET_SHOUQUAN, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap["code"];
    String msg = userMap["msg"];
   
    if (code == 1 && mounted) {
      if(userMap['data']['msg']==null){

      }else{
        url=userMap['data']['msg']['img'];
        setState(() {
          
        });
      }
    }else{
       Fluttertoast.showToast(msg: msg);
    }
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
       appBar: AppBar(
        title: Text(
          '授权证书',
          style: TextStyle(color: black, fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
        ),
        elevation:0.2,
        backgroundColor: white,
        iconTheme: new IconThemeData(color: black_99),
        brightness: Brightness.light,
         actions: <Widget>[
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            child: Container(
              alignment: Alignment.center,
              padding: EdgeInsets.fromLTRB(0, 0, 13, 0),
              child: Text(
                '申请证书',
                style: TextStyle(
                    fontSize: ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE),
                    color: mainColor),
              ),
            ),
            onTap: () {
              Navigator.of(context)
                  .push<String>(MaterialPageRoute(builder: (context) {
                return new ApplyShouQuanPage();
              }));
            },
          )
        ],
      ),
      body: Container(
        width: double.infinity,
        child: Center(
          child:url==""?Text('暂无证书',style: TextStyle(color:mainColor,fontSize:ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),):CachedNetworkImage(
                imageUrl:Api.ImgBaseUrl+url),
        ),
      ),
    );
  }
}